import * as PIXI from 'pixi.js';
import { getTextureFromCache } from '../utils';
import DelBtn from '../../../../img/delete.png';

const name = 'deleteIcon';

/**
 * 删除按钮，将元素移出舞台
 *
 * @export
 * @class DeleteIcon
 */
export default class DeleteIcon {
  icon;

  constructor(app, obj) {
    this.app = app;
    this.obj = obj;
  }

  /**
   * 创建一个删除按钮
   *
   * @return {*}
   * @memberof DeleteIcon
   */
  create() {
    const texture = getTextureFromCache(this.app, name, DelBtn); // 优先从预加载缓存中取出
    const sprite = PIXI.Sprite.from(texture);
    sprite.width = 21;
    sprite.height = 21;
    sprite.anchor.set(0.5);

    this.obj.position.y = 0;
    const rect = this.obj.getBounds();
    const { x, y } = rect;

    sprite.x = x;
    sprite.y = y;

    this.icon = sprite;
    sprite.name = 'delBtn';
    return this.icon;
  }
}
